1 #include "MessageBox.h"
3 #include "RescourceKeys.h"
4 #include "ScreenNames.h"
6 MessageBox::MessageBox(int* scrn
, ResourceMaster
* resou
, string mainMessage
, string subMessage
, string yesMessage
, string noMessage
)
11 font
= new Fonts(0, rsc
);
12 outlineAnimation
= new Animation(rsc
->gameAnimations
.at(WhiteBlueBG
));
14 font
->loadFont(SDL_Color
{ 100,100,100,00 }, yesMessage
, 2);
15 textYes
= font
->getTexture();
16 font
->loadFont(SDL_Color
{ 100,100,100,00 }, noMessage
, 2);
17 textNo
= font
->getTexture();
18 font
->loadFont(SDL_Color
{ 100,100,100,00 }, mainMessage
, 2);
19 textMessage
= font
->getTexture();
20 font
->loadFont(SDL_Color
{ 100,100,100,00 }, subMessage
, 2);
21 textSubMessage
= font
->getTexture();
23 rectMain
= {font
->prcnt(0.1, 'x'), font
->prcnt(0.1, 'y'), font
->prcnt(0.50, 'x'), font
->prcnt(0.60, 'y')};
24 rectMessage
= { font
->prcnt(0.15, 'x'), font
->prcnt(0.15, 'y'), font
->prcnt(0.4, 'x'), font
->prcnt(0.2, 'y') };
25 rectSubMessage
= { font
->prcnt(0.20, 'x'), font
->prcnt(0.30, 'y'), font
->prcnt(0.3, 'x'), font
->prcnt(0.15, 'y') };
26 rectNo
= { font
->prcnt(0.15, 'x'), font
->prcnt(0.5, 'y'), font
->prcnt(0.1, 'x'), font
->prcnt(0.1, 'y') };
27 rectYes
= { font
->prcnt(0.30, 'x'), font
->prcnt(0.5, 'y'), font
->prcnt(0.1, 'x'), font
->prcnt(0.1, 'y') };
33 MessageBox::~MessageBox()
37 void MessageBox::boxLoop()
39 chrono::milliseconds ms
= chrono::duration_cast
<chrono::milliseconds
>(
40 chrono::system_clock::now().time_since_epoch());
49 ms
= chrono::duration_cast
<chrono::milliseconds
>(
50 chrono::system_clock::now().time_since_epoch());
58 while (expired
- initial
< FPSDelay
) {
59 ms
= chrono::duration_cast
<chrono::milliseconds
>(
60 chrono::system_clock::now().time_since_epoch());
67 void MessageBox::processInput()
70 while (SDL_PollEvent(&evnt
)) {
77 SDL_GetMouseState(&x
, &y
);
79 case SDL_MOUSEBUTTONDOWN
:
82 case SDL_MOUSEBUTTONUP
:
89 void MessageBox::update() {
90 if (x
> rectNo
.x
&& x
< (rectNo
.x
+ rectNo
.w
) && y
> rectNo
.y
&& y
< (rectNo
.y
+ rectNo
.h
)) {
94 else if (x
> rectYes
.x
&& x
< (rectYes
.x
+ rectYes
.w
) && y
> rectYes
.y
&& y
< (rectYes
.y
+ rectYes
.h
)) {
116 void MessageBox::play() {
120 void MessageBox::render() {
122 SDL_RenderCopy(rsc
->rendPtr
, rsc
->gameBG
.at(LangBG
), NULL
, &rectMain
);
125 SDL_RenderCopy(rsc
->rendPtr
, outlineAnimation
->itterateAnimation(30), NULL
, &rectNo
);
128 SDL_RenderCopy(rsc
->rendPtr
, outlineAnimation
->itterateAnimation(30), NULL
, &rectYes
);
130 SDL_RenderCopy(rsc
->rendPtr
, textYes
, NULL
, &rectYes
);
131 SDL_RenderCopy(rsc
->rendPtr
, textNo
, NULL
, &rectNo
);
132 SDL_RenderCopy(rsc
->rendPtr
, textMessage
, NULL
, &rectMessage
);
133 SDL_RenderCopy(rsc
->rendPtr
, textSubMessage
, NULL
, &rectSubMessage
);
135 SDL_RenderPresent(rsc
->rendPtr
);
138 void MessageBox::close() {
139 SDL_DestroyTexture(textYes
);
140 SDL_DestroyTexture(textNo
);
141 SDL_DestroyTexture(textMessage
);
142 SDL_DestroyTexture(textSubMessage
);
145 delete outlineAnimation
;
148 bool MessageBox::getResponse() {